Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[781] Add support for multiline labels #1087

Merged
merged 1 commit into from
Mar 8, 2022
Merged

Conversation

lfasani
Copy link
Contributor

@lfasani lfasani commented Mar 4, 2022

Type of this PR

  • Bug fix
  • [ X ] New feature or improvement
  • Documentation
  • Cleanup
  • Test
  • Build/Releng

Issue(s)

...

What does this PR do?

...

Screenshot/screencast of this PR

...

Potential side effects

...

How to test this PR?

  • Frontend Unit tests
  • Backend Unit tests
  • Cypress : please specify
  • Manual Test : please specify

Checklist

  • I have read CONTRIBUTING carefully.
  • I have signed the Contributor License Agreement.
  • All my commits are signed-off (-s) with my mail address of my Eclipse Account.
  • I have covered my changes by unit tests or integration tests or manual tests.
  • All tests pass.
  • I have updated the documentation accordingly
  • New React components are availables in storybook

@lfasani lfasani requested a review from sbegaudeau March 4, 2022 10:30
@sbegaudeau sbegaudeau changed the title Lfa/enh/multiline label [781] Add support for multiline labels Mar 4, 2022
@sbegaudeau sbegaudeau added this to the 2022.03.0 milestone Mar 4, 2022
@lfasani lfasani force-pushed the lfa/enh/borderNode2 branch from c4ebc5e to d328757 Compare March 4, 2022 13:29
@lfasani lfasani force-pushed the lfa/enh/multilineLabel branch 2 times, most recently from ef37e1f to 55c90bb Compare March 4, 2022 13:34
Copy link
Member

@sbegaudeau sbegaudeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build of the pull request is red and please try not to create pull requests between your own branches but instead against master so that we have a better idea of the real impact on the work of this branch.

Comment on lines +80 to +84
if (!node.isBorderNode()) {
// The label is positioned at the center of the node and the front-end will apply a "'text-anchor':
// 'middle'" property.
xOffSet = node.getLabel().getSize().getWidth() / 2;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can make this hypothesis if in the class below, we have the code to deal with various label placement strategies? What was the issue with the previous algorithm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not catch your first sentence.

What was the issue with the previous algorithm?

The frontend needs to display the label area centered on the node and each line part centered inside the node
I used "text-anchor:middle" to do that. But to make it work the label position needs to be positionned on the center of the node. I tried to apply text-anchor:middle only on tspan instead of the parent text but text-anchor:middle make still the line positionned on the label x position

Comment on lines +97 to +100
public Diagram performElKLayout(IEditingContext editingContext, Diagram diagram) {
return this.layoutService.layout(editingContext, diagram);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used to perform the elk layout

@@ -39,7 +39,7 @@
public class EStringIfDescriptionProvider {
private static final String IF_DESCRIPTION_ID = "EString"; //$NON-NLS-1$

private static final String TEXTFIELD_DESCRIPTION_ID = "Textfield"; //$NON-NLS-1$
private static final String TEXTAREA_DESCRIPTION_ID = "Textarea"; //$NON-NLS-1$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this file needs to be changed? Using a textfield does not change anything at all on the behavior of the frontend nor on this feature, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ths is needed because the frontend component TextfieldPropertySection checks the typeName if it equals 'Textarea'

frontend/src/diagram/sprotty/DependencyInjection.ts Outdated Show resolved Hide resolved
frontend/src/diagram/sprotty/views/LabelView.tsx Outdated Show resolved Hide resolved
frontend/src/diagram/sprotty/views/LabelView.tsx Outdated Show resolved Hide resolved
@sbegaudeau sbegaudeau force-pushed the lfa/enh/borderNode2 branch from d328757 to 134546e Compare March 7, 2022 10:28
Base automatically changed from lfa/enh/borderNode2 to master March 7, 2022 10:34
@sbegaudeau sbegaudeau linked an issue Mar 7, 2022 that may be closed by this pull request
4 tasks
@lfasani lfasani force-pushed the lfa/enh/multilineLabel branch from 55c90bb to 69bc5f4 Compare March 7, 2022 13:52
@lfasani lfasani requested a review from sbegaudeau March 7, 2022 16:34
@lfasani lfasani force-pushed the lfa/enh/multilineLabel branch 2 times, most recently from 1bd6265 to ad373c4 Compare March 8, 2022 13:52
The changes are about the node label center position.
There is in fact no visible change but there are technical changes to
prepare the following commits when we will have a label on many lines:

* the label position given by the server is the horizontal center of the
node instead of the left position of the label
* consequently the LabelView is updated to display the text with
'text-anchor': 'middle' instead of the default 'text-anchor': 'start'

The default form description will now use a text area for default form
representation. It will allow multiple line edition. Shift + return in
a text area only adds a line return but does not send the mutation.

Adapt the ELK to consider the multiple line. The ELK label TextBound is
set according the line returns contained in the label text.
This will allow to have the right width of the node and to avoid the
overlap of the label text with the contained nodes.

Add a isMultiLine attribute to Label so that it can be seen as a text area
by sprotty. Adapt the editing bounds and the edited text font to have always
the same editing area whatever the zoom level.

Bug: #781
Signed-off-by: Laurent Fasani <[email protected]>
@sbegaudeau sbegaudeau force-pushed the lfa/enh/multilineLabel branch from ad373c4 to b4ac4ea Compare March 8, 2022 15:27
Copy link
Member

@sbegaudeau sbegaudeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just wait for the build and merge it after that

Comment on lines 58 to 79
const Text = () => {
const lines = text.split('\n');
if (lines.length == 1) {
return text;
} else {
return lines.map((line, index) => {
if (index === 0) {
return <tspan x="0">{line}</tspan>;
} else {
if (line.length == 0) {
// avoid tspan to be ignored if there is only a line return
line = ' '; //$NON-NLS-1$
}
return (
<tspan x="0" dy={fontSize}>
{line}
</tspan>
);
}
});
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component can be extracted and given props. Overwise its lifecycle is a bit odd since it is based on a closure

@sbegaudeau sbegaudeau merged commit 34f6823 into master Mar 8, 2022
@sbegaudeau sbegaudeau deleted the lfa/enh/multilineLabel branch March 8, 2022 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for multilines labels
2 participants